package com.base.service.impl;

import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import com.base.lock.RedisLock;
import com.base.service.UserService;

@Service
public class UserServiceImpl implements UserService{

	@RedisLock(prefix = "user:",key = "userId")
	@Override
	public Object doSomething(Long userId) {
		try {
			System.out.println("开始执行业务方法userId:"+userId);
			Thread.sleep(10000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		return "success";
	}

	@Cacheable(value= "cache",key = "'test'")
	@Override
	public String cacheTest() {
		System.out.println("模拟读取数据库");
		return "cacheTest";
	}
	
	@Cacheable(value= "cacheTTL",key = "'test'")
	@Override
	public String cacheTTLTest() {
		System.out.println("模拟读取数据库TTL");
		return "cacheTest";
	}

}
